{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Add Cloud Optimized GeoTIFF\n",
    "\n",
    "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/108_add_geotiff.ipynb)\n",
    "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/notebooks/108_add_geotiff.ipynb)\n",
    "[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
    "\n",
    "This example demonstrates how to use `leafmap.foliumap.Map.add_geotiff` to load a Cloud Optimized GeoTIFF (COG) directly in the browser using the [georaster-layer-for-leaflet](https://github.com/GeoTIFF/georaster-layer-for-leaflet) plugin."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# %pip install leafmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import leafmap.foliumap as leafmap"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "Visualizing multi-band GeoTIFFs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = leafmap.Map()\n",
    "cog_url = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_naip.tif\"\n",
    "m.add_geotiff(cog_url, name=\"NAIP\", indexes=[1, 2, 3])\n",
    "m.add_layer_control()\n",
    "m.add_opacity_control()\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "Visualizing single-band GeoTIFFs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = leafmap.Map()\n",
    "cog_url = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_hag.tif\"\n",
    "m.add_geotiff(\n",
    "    cog_url,\n",
    "    name=\"HAG\",\n",
    "    vmin=0,\n",
    "    vmax=10,\n",
    "    palette=\"terrain\",\n",
    ")\n",
    "m.add_layer_control()\n",
    "m.add_opacity_control()\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "Visualizing multiple layers simultaneously"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = leafmap.Map()\n",
    "naip_url = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_naip.tif\"\n",
    "hag_url = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_train_hag.tif\"\n",
    "\n",
    "m.add_geotiff(\n",
    "    naip_url,\n",
    "    name=\"NAIP\",\n",
    ")\n",
    "m.add_geotiff(\n",
    "    hag_url,\n",
    "    name=\"HAG\",\n",
    "    vmin=0,\n",
    "    vmax=10,\n",
    "    palette=\"terrain\",\n",
    ")\n",
    "\n",
    "in_geojson = \"https://huggingface.co/datasets/giswqs/geospatial/resolve/main/las_vegas_buildings_train.geojson\"\n",
    "m.add_geojson(in_geojson, layer_name=\"Buildings\")\n",
    "\n",
    "m.add_layer_control()\n",
    "m.add_opacity_control()\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "geo",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
